<style>

</style>
<div class="page">
  <div class="list-block">
    <ul>
      <!-- Text inputs -->
      <li>
        <div class="item-content">
          <div class="item-inner">
            <div class="item-title label">收件人</div>
            <div class="item-input">
              <input class="name" type="text" placeholder="姓名" />
            </div>
          </div>
        </div>
      </li>
      <li>
        <div class="item-content">
          <div class="item-inner">
            <div class="item-title label">联系方式</div>
            <div class="item-input">
              <input type="text" class="phone" placeholder="电话" />
            </div>
          </div>
        </div>
      </li>
      <li>
        <div class="item-content">
          <div class="item-inner">
            <div class="item-title label">地区</div>
            <div class="item-input">
              <input type="text" id='city-picker'/>
            </div>
          </div>
        </div>
      </li>
      <li>
        <div class="item-content">
          <div class="item-inner">
            <div class="item-title label">详细地址</div>
            <div class="item-input">
              <input class="address" type="text" placeholder="街道、楼牌号等" />
            </div>
          </div>
        </div>
      </li>
      <li>
        <div class="item-content">
          <div class="item-inner">
            <div class="item-title label">设为默认</div>
            <div class="item-input">
              <label class="label-switch">
                <input type="checkbox" />
                <div class="checkbox"></div>
              </label>
            </div>
          </div>
        </div>
      </li>



    </ul>
    <a style="margin: 1rem;" class="button button-big button-fill button-success btn-save">保存</a>

  </div>

</div>

<script>
  $(function(){
    $("#city-picker").cityPicker({
      toolbarTemplate: '<header class="bar bar-nav">\
                          <button class="button button-link pull-right close-picker">确认</button>\
                          <h1 class="title">选择地区</h1>\
                        </header>'
    });
    //电话
    function checkTel(value){
      var isPhone = /^([0-9]{3,4}-)?[0-9]{7,8}$/;
      var isMob=/^((\+?86)|(\(\+86\)))?(13[012356789][0-9]{8}|15[012356789][0-9]{8}|18[02356789][0-9]{8}|147[0-9]{8}|1349[0-9]{7})$/;
      if(isMob.test(value)||isPhone.test(value)){
        return true;
      }else{
        $.toast("电话不正确");
        return false;
      }
    }

    $('.btn-save').click(function(){
        //姓名
        var name = $('.name').val();
        if(name.replace(/[ ]/g,"").length == 0){
          $.toast("姓名不能为空");
          return;
        }
        //电话
        var phone = $('.phone').val();
        if(!checkTel(phone)) return;
        //地区
        var city = $('#city-picker').val();
        //地址
        var street = $('.address').val();
        var msg = {
            name : name,
            phone : phone,
            country : "xzxsadfas",
            province : "dsfdsa",
            city : "dsafdsf",
            street : street,
            isDefault : 1,
        };
        console.log(msg);
        $.post('/user/addAddress',msg,function(res){
          console.log(res);
        });
    });

  })
</script>
